/**
 * Created by BIYY on 2018-6-23.
 */
module.exports = {
  getParam(key:any) {
    return this.getParamAll()[key] || '';
  },

  getParamAll() {
    let param = {};
    const queryStr = location.href.split('?');
    if (queryStr.length < 2) {
      return param;
    }
    const params = queryStr[1].split('&');
    params.forEach((item) => {
      const arr = item.split('=');
      const key = arr[0];
      const value = arr[1];
      param[key] = value;
    });
    return param;
  },
  objToUrl(url:string,params:any) {
      let paramsArray:any = [];
      Object.keys(params).forEach(key => paramsArray.push(key + '=' + params[key]));
      if (url.search(/\?/) === -1) {
          url += '?' + paramsArray.join('&');
      }
      else {
          url += '&' + paramsArray.join('&');
      }

      return url;
  },
  urlEncode(url:any, param:any, key:any, encode:any) {
    return url.concat('?').concat(this.objToUrl(param, key, encode).slice(1));
  }
};
